package com.qidian.buy.controller;

import com.qidian.buy.entity.Category;
import com.qidian.buy.service.ICategoryService;
import com.qidian.buy.util.pojo.LayuiTableDTO;
import com.qidian.buy.util.pojo.QDResult;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author 郭浩
 */
@RestController
@RequestMapping("/category")
@CrossOrigin
public class CategoryController {
    @Resource
    private ICategoryService categoryService;
    @RequestMapping("/save")
    public QDResult save(Category category){
        return categoryService.save(category);
    }
    @RequestMapping("/get")
    public QDResult get(Long id){
        return categoryService.get(id);
    }
    @RequestMapping("/edit")
    public QDResult edit(Category category){
        return categoryService.update(category);
    }
    @RequestMapping("/query")
    public LayuiTableDTO<Category> query(Category category, @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10")int limit){
        return categoryService.query(page,limit,category);
    }
    @RequestMapping("/queryParent")
    public QDResult queryParent(){
        return categoryService.queryAllFirstLevel();
    }
    @RequestMapping("/queryByParentId")
    public QDResult queryByParentId(Long id){
        return categoryService.queryByParentId(id);
    }
    @RequestMapping("/loadTopLevel")
    public QDResult loadTopLevel(){
        return categoryService.queryAllFirstLevel();
    }
}
